/**
  ******************************************************************************
  * @file    Project/STM32F10x_StdPeriph_Template/main.c 
  * @author  MCD Application Team
  * @version V3.4.0
  * @date    10/15/2010
  * @brief   Main program body
  ******************************************************************************
  * @copy
  *
  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  *
  * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
  */ 

/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* Private function prototypes -----------------------------------------------*/
#ifdef __GNUC__
  /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
     set to 'Yes') calls __io_putchar() */
  #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
  #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */

PUTCHAR_PROTOTYPE
{
	USART_SendData(USART3, (uint8_t) ch);
	while (USART_GetFlagStatus(USART3, USART_FLAG_TC) == RESET)
	{}
	return ch;
}

/** @addtogroup STM32F10x_StdPeriph_Template
  * @{
  */

void SysTick_Configuration(void)
{
	SysTick_Config(SystemCoreClock /1000);	// 1ms
}

void SysTick_AppsCaller()
{
	VTimerService();
	ReadBatterryLevel();
	//Time_Show();
}

void BoardInit(void){
	SysTick_Configuration();
	VTimerInitController();		
	LedInitController();
	UARTInit();
	GSMInitController();
	GPSInitController();
	ChargeInitController();
	RTCInitController();
	
}

/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  	/*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f10x_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
       */ 
	uint8_t temp = 0;
 	SystemInit();
	BoardInit();
 	//printf("%s","1");
 	//printf("%s\n","GPSTracking");
	temp = VTimerGetID();
	VTimerSet(temp,500);
	while (1)
	{
		
		/* if(UART_DEBUG_RXAvailable()){	
			temp = UART_DEBUG_ReceivedByte();	
			if (temp == 'a'){
				LedOn(LED1);
				UART_DEBUG_SendByte('a');
			}
			else if (temp == 'b'){
				LedOff(LED1);
				UART_DEBUG_SendByte('b');
			}
			else if (temp == 'c'){
				LedToggle(LED1);
				UART_DEBUG_SendByte('c');
			}
			else {
				LedOn(LED0);
				UART_DEBUG_SendByte('d');
			}
		} */
		//StmChipfcGps_OutputToggle(OUTPUT_PWRKEY);
		//printf("%d\n",2);
		//printf("%d\n",GetBatterryLevel());
		//LedOn(LED0);
		//LedOff(LED1);		
		if (VTimerIsFired(temp)){
			Time_Show();
			LedToggle(LED1);
			VTimerSet(temp,1000);
		}
	}
}

/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
